package com.m2bshop.shop.controller;

import com.m2bshop.shop.pojo.Favorites;
import com.m2bshop.shop.pojo.JMFgoods;
import com.m2bshop.shop.pojo.Result.Result;
import com.m2bshop.shop.service.FavoritesService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author asus
 * @create 2022/6/14 0:10
 */
@Controller
@RequestMapping("/JMF")
public class FavoritesController {

    @Autowired
    private FavoritesService favoritesService;


    //跳转到商品页面
    @RequestMapping("/falist")
    public String falist() {

        return "JMF/Favorites";
    }

    @RequestMapping("/fqueryAll")
    @ResponseBody
    public Result queryAllgoods(HttpSession session){
        Integer userid = Integer.parseInt(session.getAttribute("userId")+"");
        List<Favorites> favoritesList = favoritesService.queryAll(userid);
        return Result.ok(favoritesList);
    }
    @RequestMapping("/dele")
    @ResponseBody
    public Result dele(HttpSession session, @Param("id") int id){
        System.out.println(id);
        Integer userid = Integer.parseInt(session.getAttribute("userId")+"");
        favoritesService.dele(id);
//        return Result.ok(favoritesList);
        return Result.ok();
    }
}
